package com.gujiayue.common.config;

import static springfox.documentation.builders.PathSelectors.regex;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {
	
	/**
	 * 创建接口扫描 访问地址 swagger-ui/index.html
	 */
	@Bean
	public Docket createRestApi() {
		Docket docket = new Docket(DocumentationType.OAS_30)
				.apiInfo(apiInfo())
				.select()
				//筛选路径
				.paths(regex("/gujiayue.*"))  
				//扫描置顶得路径 
				.apis(RequestHandlerSelectors.basePackage("com.gujiayue.module"))
				//加了ApiOperation注解的类，才生成接口文档
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				.paths(PathSelectors.any())
				.build();
		return docket;
	}

	/**
	 * 基础信息配置
	 */
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("Swagger3接口文档").description("更多请咨询服务开发者YueYa。")
				.contact(new Contact("YueYa", "http://www.yueya.cn", "2287291005@qq.com")).version("1.0").build();
	}
}